home *** CD-ROM | disk | FTP | other *** search
/ Cracking 2 / Cracking II..iso / Texty / crackme / id6-lu48-en.txt < prev    next >
Encoding:
Text File  |  1999-06-20  |  11.3 KB  |  259 lines

  1.  
  2.             -----------------------------------
  3.              Immortal Descendants CrackMe 6.0
  4.                        (by TORN@DO)
  5.             Tutorial by Lucifer48, 19 june 1999
  6.             -----------------------------------
  7.  
  8.  
  9. ======================
  10. 1. THEORETICAL APPROCH
  11. ======================
  12.  
  13. By observing the structure of the executable, we discover few things:
  14. Firstly: there are six segments 'suspicious': .CRYP, .ID60, http://L, EARN2CR, RK.CBJ., NET.
  15. The four segments .CRYP, http://L, EARN2CR, RK.CBJ. have the same size (remark: it makes me think
  16. to the packed target 'id crackme v4.0', with several segments named .Stone)
  17. We sure that the crackme is packed few times with the same packer (let's call it PACKER #2).
  18. This packer add a new segment at the end of the exe which contains informations for unpacking
  19. (as a example, see Stone's PE Encrypter 1.13 in idcrkme40.exe).
  20. Secondly: .ID60 et NET have the same size (Phys size & Virt size), looks like another packer
  21. (let's call it PACKER #1), used twice times.
  22. Thirdly: the entrypoint is: RVA: 00019319h
  23. The "319" don't evocate you something ??? The size of a segment packed with PACKER #2...
  24. It appears that, PACKER #1 insert his code at the end of the last segment (change the length),
  25. and pack the exe (we will see how and where after).
  26.  
  27. Finaly: we have this:
  28.   initial exe (unpacked)
  29. + pack 2 times with PACKER #2
  30. + pack 1 time  with PACKER #1
  31. + pack 4 times with PACKER #2
  32. + pack 1 time  with PACKER #1
  33. ------------------------------
  34. = idcrkme60.exe
  35.  
  36.  
  37. =====================
  38. 2. STUDY OF PACKER #1
  39. =====================
  40.  
  41. We load the crackme with the symbol loader, EAX=00419319 (entrypoint):
  42.  
  43. XXXX:00419319  PUSHFD                           ;save flags in the stack (on 32 bits)
  44. XXXX:0041931A  PUSH EBP
  45. XXXX:0041931B  CALL 0041940C                    ;not interesting (very short call)
  46. XXXX:00419320  XCHG EDX,EBP
  47. XXXX:00419322  POP  EBP
  48. XXXX:00419323  PUSHAD                           ;save registers
  49. XXXX:00419324  XCHG EDX,EBP                     ;ebp=00016CFE
  50. XXXX:00419326  CMP  BYTE PTR [EBP+00412715],01
  51. XXXX:0041932D  JZ   00419368                    ;(no jump)
  52. XXXX:0041932F  MOV  BYTE PTR [EBP+00402715],01
  53. XXXX:00419336  JMP  0041941F
  54.  
  55. we continue:
  56.  
  57. XXXX:0041941F  CALL 0041943F
  58. XXXX:00419424  MOV  ESP,[ESP+08]
  59. XXXX:00419428  CALL 0041940C                    ;not interesting (very short call)
  60. XXXX:0041942D  MOV  BYTE PTR [EBP+004026CC],C3
  61. XXXX:00419434  CALL 00419384                    ;HERE, call to explore!! (*)
  62. XXXX:00419439  JMP  00419354
  63.  
  64. (*) This call is very important, because it's the unpacking routine.
  65.  
  66. XXXX:00419384  LEA  EDI,[EBP+004026CD]         ;offset RVA (it's an "array" of few RVA)
  67. XXXX:0041938A  MOV  ESI,[EDI]                  ;RVA        (see remark below)
  68. XXXX:0041938C  OR   ESI,ESI                    ;if ESI=0, we have unpacked every segments
  69. XXXX:0041938E  JZ   004193C1
  70. XXXX:00419390  ADD  ESI,[EBP+0040270D]         ;add the image base (00400000)
  71. XXXX:00419396  MOV  ECX,[EDI+04]               ;length of the area to unpack (Phys size)
  72. XXXX:00419399  PUSH EDI
  73. XXXX:0041939A  MOV  EDI,ESI
  74. ...
  75. unpack 32 bits per 32 bits (ADD / XOR / ROR / SUB)
  76. ...
  77. XXXX:004193B5  STOSD                           ;<=> MOV [EDI],EAX / ADD EDI,4
  78. XXXX:004193B6  SUB  ECX,04
  79. XXXX:004193B9  JAE  004193A6                   ;while ecx<>0, we continue
  80. XXXX:004193BB  POP  EDI
  81. XXXX:004193BC  ADD  EDI,08                     ;next area (segment) to unpack
  82. XXXX:004193BF  JMP  0041938A                   ;jump, see above
  83. XXXX:004193C1  RET                             ;end of call 00419384
  84.  
  85. Remark:
  86. -----IDCRKME60!NET+03C2---------------------------byte--------------PROT---(0)--
  87. XXXX:004193C2 00 10 00 00 08 0A 00 00-00 40 00 00 10 03 00 00  .........@......
  88. XXXX:004193D2 00 30 01 00 19 03 00 00-00 40 01 00 00 06 00 00  .0.......@......
  89. XXXX:004193E2 00 60 01 00 19 03 00 00-00 70 01 00 19 03 00 00  ..`......p......
  90. XXXX:004193F2 00 00 00 00                                      ....
  91. ---------------------------------------------------------------------------------
  92.  
  93. We recognize sizes (Phys size) and adress of the different segments, which are unpacked.
  94. Maybe this array is more clear:
  95.  
  96. RVA       Phys size    Name
  97. 00401000    A08        .text           ;first loop
  98. 00404000    310        .data           ;second loop
  99. 00413000    319        .CRYP           ;third loop
  100. 00414000    600        .ID60           ;4th loop
  101. 00416000    319        http://L        ;5th loop
  102. 00417000    319        EARN2CR         ;6th loop
  103.  
  104. this is the end of the packer's code (very *classical* end):
  105.  
  106. XXXX:00419374  POPAD                           ;reload registers
  107. XXXX:00419375  POPFD                           ;reload flags
  108. XXXX:00419376  MOV  EBX,[EDX+00402709]         ;EBX=00419000 (segment NET)
  109. XXXX:0041937C  MOV  [EDX+00402709],ECX
  110. XXXX:00419382  JMP  EBX                        ;end of PACKER #1
  111.  
  112.  
  113. Everything all right, PACKER #1 has done its job and jump to EBX (this is the PACKER #2's turn).
  114.  
  115.  
  116. =====================
  117. 3. STUDY OF PACKER #2
  118. =====================
  119.  
  120. It begins like this:
  121.  
  122. XXXX:00419000  PUSH EBP
  123. XXXX:00419001  PUSH EDI
  124. XXXX:00419002  PUSH ESI
  125. XXXX:00419003  PUSH EDX
  126. XXXX:00419004  PUSH ECX
  127. XXXX:00419005  PUSH EBX
  128. XXXX:00419006  CALL 0041900B
  129. XXXX:0041900B  POP EBP                            ;good trick to obtain the current adress
  130.  
  131. we continue:
  132.  
  133. XXXX:00419025  CALL 004190C3
  134. XXXX:0041902A  CMP  DWORD PTR [EBP+0040378F],00   ;we have [EBP+0040378F]=0 
  135. XXXX:00419031  JZ   0041907F                      ;jmp = exit the program, no unpacking
  136. XXXX:00419033  SUB  EDX,[EBP+00403655]
  137. XXXX:00419039  SUB  EDX,0B
  138. XXXX:0041903C  MOV  [EBP+0040365D],EDX            ;save image base (here: 00400000)
  139. XXXX:00419042  MOV  ESI,004037B7                  ;small buffer of 8*32 bits
  140. XXXX:00419047  ADD  ESI,EBP                       ;buffer located in the current segment (NET)
  141. XXXX:00419049  PUSH ESI
  142. XXXX:0041904A  CALL [EBP+00403793]                ;CALL [KERNEL32!GetLocalTime]
  143. XXXX:00419050  CMP  WORD PTR [EBP+004037B9],01    ;month
  144. XXXX:00419058  JB   0041908B                      ;jump to the unpack routine
  145. XXXX:0041905A  CMP  WORD PTR [EBP+004037B7],07D0  ;year
  146. XXXX:00419063  JB   0041908B                      ;jump to the unpack routine
  147. XXXX:00419065  MOV  EAX,00403769
  148. XXXX:0041906A  ADD  EAX,EBP                       ;d EAX: "Ding Boy's PE-lockv0.07    1999-2000"
  149. XXXX:0041906C  MOV  EBX,004037F9
  150. XXXX:00419071  ADD  EBX,EBP                       ;d EBX: "  " (two space chars)
  151. XXXX:00419073  PUSH 00                            ;MB_OK
  152. XXXX:00419075  PUSH EAX                           ;offset text
  153. XXXX:00419076  PUSH EBX                           ;offset title
  154. XXXX:00419077  PUSH 00                            ;no handle
  155. XXXX:00419079  CALL [EBP+0040378F]                ;CALL [USER32!MessageBoxA]
  156. XXXX:0041907F  MOV  EAX,FFFFFFFF                  ;exit the program (nothing has been unpacked)
  157.  
  158. Few explainations: the call 004190C3; it is used to fix system adress (api call), indeed
  159. PACKER #2 may have to use CALL [KERNEL32!GetLocalTime] or/and CALL [USER32!MessageBoxA],
  160. and that's the job of the call 004190C3 to find these adress. Three cases are possible:
  161. * everything ok, system (api) adress have been found => we jump to the unpacking proc.
  162. * we are in year 2000, we receive a messagebox, the unpacking isn't done.
  163. * for a unknown reason, PACKER #2 didn't find these adress, still here, the unpacking isn't done.
  164.  
  165. In our case, it is the last proposal (for a unknown reason, no unpacking, exit/close the program).
  166. But I want to unpack this crackme! So i won't jump in 0041907F (with JZ 0041907F), i will nop this
  167. and continue until XXXX:00419042, here i will do in soft-ice: r eip=0041908B, to jump in the
  168. unpack routine.
  169. Remark: of course, we mustn't try to run api call, because we immediatly get a GFP
  170. (General Protection Fault). Remenber that adress of [KERNEL32!GetLocalTime] and
  171. [USER32!MessageBoxA] haven't been found.
  172.  
  173. This is the unpacking proc:
  174.  
  175. XXXX:00419092  CMP  DWORD PTR [ESI],00            ;still a segment to unpack ?
  176. XXXX:00419095  JZ   004190AD                      ;if yes => (no jump)
  177. XXXX:00419097  MOV  EBX,[EBP+0040365D]            ;00400000
  178. XXXX:0041909D  ADD  EBX,[ESI]
  179. XXXX:0041909F  MOV  ECX,[ESI+04]                  ;size of area (the segment)
  180. XXXX:004190A2  SUB  BYTE PTR [EBX],01             ;"unpack": very very simple!
  181. XXXX:004190A5  INC  EBX                           ;byte per byte...
  182. XXXX:004190A6  LOOP 004190A2                      ;loop
  183. XXXX:004190A8  ADD  ESI,08                        ;[ESI+0]: RVA, [ESI+4]: size
  184. XXXX:004190AB  JMP  00419092                      ;loop
  185. XXXX:004190AD  MOV  EAX,[EBP+00403659]            ;00018000
  186. XXXX:004190B3  MOV  EBX,[EBP+0040365D]            ;00400000
  187. XXXX:004190B9  ADD  EAX,EBX                       ;00418000 (RK.CJB.)
  188. XXXX:004190BB  POP  EBX
  189. XXXX:004190BC  POP  ECX
  190. XXXX:004190BD  POP  EDX
  191. XXXX:004190BE  POP  ESI
  192. XXXX:004190BF  POP  EDI
  193. XXXX:004190C0  POP  EBP
  194. XXXX:004190C1  JMP  EAX                           ;end of PACKER #2
  195.  
  196. This unpacking routine is very easy...
  197.  
  198.  
  199. ===================
  200. 4. PRACTICAL METHOD
  201. ===================
  202.  
  203. It's time to unpack this crackme.
  204.  
  205.  Begin         End         Segment      Owner               Unpacked segments
  206. 00419319  *  00419382  *  NET       *  PACKER #1  *  .text .data .CRYP .ID60 http://L EARN2CR
  207. 00419000  *  004190C1  *  NET       *  PACKER #2  *  .text .data
  208. 00418000  *  004180C1  *  RK.CJB.   *  PACKER #2  *  .text .data
  209. 00417000  *  004170C1  *  EARN2CR   *  PACKER #2  *  .text .data
  210. 00416000  *  004160C1  *  http://L  *  PACKER #2  *  .text .data
  211. 00414319  *  00414382  *  .ID60     *  PACKER #1  *  .text .data .CRYP .ID60
  212. 00414000  *  004140C1  *  .ID60     *  PACKER #2  *  .text .data
  213. 00413000  *  004130C1  *  .CRYP     *  PACKER #2  *  .text .data
  214. 004011CB  <--- guess what it is!!!
  215.  
  216. We you arrive at the end of the last unpacking proc (XXXX:004130C1 JMP EAX); don't forget to
  217. dump the process... (under soft-ice, press A then JMP EIP to put the program in a infinite loop,
  218. press F5 and launch Procdump).
  219.  
  220. Don't forget too, to change the entrypoint (11CB) in the new exe. The crackme is unpacked!!!!!
  221.  
  222.  
  223. =================================
  224. 5. RE-ENABLING THE REQUEST BUTTON
  225. =================================
  226.  
  227. Windows are created with the api call "DialogBoxParamA", so we must have a look in the
  228. "dialog box procedure", juste before the check (if we have pressed a button, message 
  229. WM_COMMAND = 0111h), we see another message: WM_INITDIALOG (= 0110h), which, as his name
  230. indicate... we see the api call EnableWindow, and just before:
  231.  
  232. :004012E9 837DFC00                cmp dword ptr [ebp-04], 00000000
  233. :004012ED 7515                    jne 00401304
  234.  
  235. if [ebp-04]=0 the button (request) is disabled (in the main window).
  236. So change: JNE => JMP
  237. After:
  238.  
  239. :00401379 837DFC00                cmp dword ptr [ebp-04], 00000000
  240. :0040137D 751C                    jne 0040139B
  241.  
  242. same thing here!
  243.  
  244. Remark: if you only patch the first JNE, the (request) button will be enabled but it will
  245. activate nothing! The dialog box "Request" won't be created.
  246.  
  247.  
  248. =============
  249. 6. CONCLUSION
  250. =============
  251.  
  252. That's all for this crackme! No more to say...
  253. Greetings: TORN@DO (of course, for his crackme), Volatility (will we work together ?),
  254.            Eternal Bliss (for his site), MiZ (what a good essay for idcrkme5.0), ACiD BuRN,
  255.            and others people i forgot.
  256.  
  257.  
  258. Lucifer48
  259.